package com.toolkit.util;
import com.aspose.cells.License;
import com.aspose.cells.SaveFormat;
import com.aspose.cells.Workbook;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.Resource;
import org.springframework.stereotype.Component;

import java.util.Objects;
@Component
public class AsposeUtil {
    @Value("classpath:excel-license.xml")
    private  Resource resource;
    /**
     * 获取 license 去除水印
     * 若不验证则转化出的pdf文档会有水印产生
     */
//    private static void getLicense() throws Exception {
//        License license = new License();
//        license.setLicense(Objects.requireNonNull(resource.getInputStream()));
//    }

   public void  excelToPdf(String excelPath,String pdfPath) throws Exception {
       License license = new License();
       license.setLicense(Objects.requireNonNull(resource.getInputStream()));
        Workbook workbook = new Workbook(excelPath);
        // Save as PDF
        workbook.save(pdfPath, SaveFormat.PDF);
    }

}
